package main;

import java.awt.Graphics;
import java.io.IOException;

public class Entity {
	
	protected double dx = 10;
	protected double dy = 100;
	
	protected double x = 50;
	protected double y = 50;
	
	private Sprite entitySprite;
	
	public Entity( String ref, long x, long y ) {
		SpriteStore store = SpriteStore.get();
		this.x = x;
		this.y = y;
		try {
			store.loadImage(ref);
			entitySprite = store.getSprite( ref );
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	
	public void move( long delta ) {
		x += ( delta * dx ) / 1000;
		y += ( delta * dy ) / 1000;
	}
	
	public void draw( Graphics g ) {
		entitySprite.draw( g,(int)x, (int)y );
	}
	
	/**
	 * Set the horizontal speed of this entity
	 * 
	 * @param dx The horizontal speed of this entity (pixels/sec)
	 */
	public void setHorizontalMovement(double dx) {
		this.dx = dx;
	}

	/**
	 * Set the vertical speed of this entity
	 * 
	 * @param dx The vertical speed of this entity (pixels/sec)
	 */
	public void setVerticalMovement(double dy) {
		this.dy = dy;
	}	
	
	public Sprite getSprite() {
		return entitySprite;
	}
	
	public double getX() {
		return x;
	}
	
	public double getY() {
		return y;
	}

}
